/*
 * @Author: Starfish_DL
 * @Date: 2020-11-07 13:17:53
 * @LastEditors: Starfish_DL
 * @LastEditTime: 2020-11-08 13:54:40
 * @CurrentVersion: 1.0
 * @Description: 
 */
public class Ticket implements Runnable {
    private int tick = 100;

    @Override
    public synchronized void run() {
        while (this.tick > 0) {
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                System.out.println(e.getStackTrace());
                //DONE: handle exception
            }
            System.out.println("售出车票，tick号为：" + this.tick--);
        }
    }
}

/**
 * TicketDemo
 */
class TicketDemo {

    public static void main(String[] args) {
        Ticket ticket1 = new Ticket();
        Thread t1 = new Thread(ticket1, "1号窗口");
        Thread t2 = new Thread(ticket1, "2号窗口");
        Thread t3 = new Thread(ticket1, "3号窗口");
        t1.start();
        t2.start();
        t3.start();
    }
}